<template>
  <div>
    <div class="common-layout">
      <el-container>
        <el-aside width="200px" direction="vertical"><div>
          <div style="display: flex; width: 200px; justify-content: flex-end; align-items: flex-end">
            <el-avatar :size="75" :src="this.inform.img"></el-avatar></div>
        </div></el-aside>
        <el-main>
          <div >
            <el-descriptions :title="this.info.name" class="margin-top" size="">
              <template #extra>
                <el-button type="primary" @click="this.$router.back()">返回</el-button>
              </template>
              <el-descriptions-item label="项目类别">{{this.info.type}}</el-descriptions-item>

              <el-descriptions-item label="合作单位">{{this.info.cooperationUnit}}</el-descriptions-item>
              <el-descriptions-item label="自然基金">{{this.info.naturalFund}}</el-descriptions-item>
              <el-descriptions-item label="分数">{{this.info.score}}</el-descriptions-item>
              <el-descriptions-item label="审核状态">
                <el-tag
                    :type="this.info.status === '审核中' ? 'primary' : 'success'"
                    disable-transitions>{{this.info.status}}</el-tag>
              </el-descriptions-item>
              <el-descriptions-item label="上传时间"
              >{{this.info.uploadTime}}
              </el-descriptions-item
              >
              <el-descriptions-item label="下载"><a :href="this.info.download">点击下载</a></el-descriptions-item>
              <el-descriptions-item label="起始日期">{{this.info.year}}</el-descriptions-item>
              <el-descriptions-item></el-descriptions-item>
              <el-descriptions-item label="项目简介">{{this.info.projectDescription}}</el-descriptions-item>
            </el-descriptions>
          </div>
        </el-main>
      </el-container>
    </div>
  </div>
</template>

<script >

import  {useRouter}  from "vue-router";
import axios from "axios";
import {ElMessage} from "element-plus";
import {defineComponent, reactive, ref} from 'vue';
const visible = ref(false);

export default {
  data(){
    return {
      inform:{
        name:'',
        personalProfile:'',
        id:'',
        img:'',
        telephone:'123',
        token:''
      },
      info:{
        name: '',
        author:'',
        projectDescription:'',
        score: '',
        naturalFund:'',
        uploadTime: '',
        status: '',
        download:'',
        cooperationUnit:'',
        startEndYear:'',
        year:'',
      },
    }
  },
  created(){
    //页面加载时就从本地通过localstorage获取存储的token值
    this.token =  localStorage.getItem('ID');
    this.id = this.token;
  },
  mounted() {
    this.$http({
      method: 'get',
      url: '/user/info',
      headers: {
        //把token放到请求头才能请求，这里的'Bearer '表示是后台希望更加的安全，依据后台给的信息看到底是加还是不加
        'session':  this.token,
      }
    })
        .then(res=>{                    //请求成功后执行函数
          if(res.data.code === 0){
            //请求成功之后给用户名赋值
            this.inform.name=res.data.data.nickname;
            this.inform.personalProfile = res.data.data.personalProfile;
            this.inform.id=res.data.data.id;
            this.inform.telephone = res.data.data.telephone;
            this.inform.img = ref(res.data.data.portrait);

            console.log("登录成功")
          }else{
            console.log("登录失败")
          }
        })
        .catch(err=>{                   //请求错误后执行函
          console.log("请求错误")
        });

    console.log(this.$route)
    let num =  this.$route.query.paperId;
    console.log(num);
    axios.get(`http://139.196.160.103:8081/project?projectId=${num}`,
        {
          headers: {
            'Content-Type': 'application/json',
            'session': localStorage.getItem('ID'),
          }
        }).then(res => {
      if (res.data.code === 0) {
        this.info.type = res.data.data.type;
        this.info.projectDescription = res.data.data.projectDescription;
        this.info.score = res.data.data.score;
        this.info.name = res.data.data.name;
        this.info.uploadTime = res.data.data.uploadTime;
        this.info.author = res.data.data.memberOneName;
        this.info.download = res.data.data.filePath;
        this.info.cooperationUnit = res.data.data.cooperationUnit;
        this.info.naturalFund = res.data.data.naturalFund+" CNY";
        this.info.year = res.data.data.startEndYear;
        let alter = res.data.data.status;
        if(alter == 1) this.info.status = '已通过'
        else this.info.status = '审核中'
        console.log(res.data.data)
      } else {
        ElMessage('删除失败');
      }
    });

  },
  methods:{}
}




</script>
<style scoped>

</style>
